// 

/**
 * 缺点：
 * 1. 需要手动调用dep.addEffect()将方法添加到subscribe数组中
 * 2. 需要手动调用dep.notify()才能更新
 */

class Dep {
  constructor() {
    this.subscribe = []
  }
  addEffect(effect) {
    this.subscribe.push(effect)
  }
  notify() {
    this.subscribe.forEach((effect) => {
      effect()
    })
  }
}
const info = { name: 'zs', counter: 3 }
const dep = new Dep()

function doubleCounter() {
  console.log(info.counter * 2);
}
function powerCounter() {
  console.log(info.counter * info.counter);
}
dep.addEffect(doubleCounter)
dep.addEffect(powerCounter)
info.counter++
dep.notify()
